﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class BaseCommond
{
   public int CommondType;

   public virtual void SendToServer()
    {
      
    }
}

public class CommondQueue
{
    LinkedList<BaseCommond> CommondLst = new LinkedList<BaseCommond>();

    public void Push(BaseCommond commond)
    {
        this.CommondLst.AddLast(commond);
    }

    public BaseCommond First()
    {
        if (this.CommondLst.First == null) return null;
        return this.CommondLst.First.Value;
    }

    public BaseCommond Pop()
    {
        BaseCommond retCommond = this.CommondLst.First.Value;
        this.CommondLst.RemoveFirst();
        return retCommond;
    }
}
/*
//TODO 是否真的需要对象池?
public class CommondPool
{
    Dictionary<int, LinkedList<BaseCommond>> UseCommondDic;
    Dictionary<int, LinkedList<BaseCommond>> FreeCommondDic;

    public T UseCommond<T>(int commondType) where T :BaseCommond , new()
    {
        T commond = null;
        if (FreeCommondDic.ContainsKey(commondType) && FreeCommondDic[commondType].Count > 0)
        {
            commond = (T)FreeCommondDic[commondType].First.Value;
            FreeCommondDic[commondType].RemoveFirst();
            return commond;
        }
        else
        {
             commond = new T();
        }
        if (!UseCommondDic.ContainsKey(commondType))
        {
            UseCommondDic.Add(commondType, new LinkedList<BaseCommond>());
        }
        UseCommondDic[commondType].AddFirst(commond);
        return commond;
    }

    public void FreeCommond(LinkedListNode<BaseCommond> commond)
    {
        if (!this.FreeCommondDic.ContainsKey(commond.Value.CommondType))
        {
            this.FreeCommondDic[commond.Value.CommondType] = new LinkedList<BaseCommond>();
        }
        this.FreeCommondDic[commond.Value.CommondType].AddFirst(commond);
    }
}
*/
